package com.example;

import com.example.dao.BookDao;
import com.example.service.BookService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class AppForLifeCycle {
    public static void main( String[] args ) {
        //ApplicationContext ctx = new ClassPathXmlApplicationContext("applicationContext.xml");
        //为了关闭容器，使用close方法，但是ApplicationContext中没有这个方法，所以使用ClassPathXmlApplicationContext
        ClassPathXmlApplicationContext ctx1 = new ClassPathXmlApplicationContext("applicationContext.xml");

        /*BookDao bookDao = (BookDao) ctx1.getBean("bookDao");
        bookDao.save();*/

        BookService bookService = (BookService) ctx1.getBean("bookService");
        bookService.save();
        //注册关闭钩子函数，在虚拟机退出之前回调此函数，关闭容器
        //ctx.registerShutdownHook();
        //关闭容器
        ctx1.close();
    }
}
